/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DB;

/**
 *
 * @author Asus
 */
import java.sql.*;
public class DB {
    private Connection connection;
    private Statement stat;
    private ResultSet result;

    public DB(){
        String db_url = "jdbc:mysql://localhost/bropsdox";
        String db_user = "root";
        String db_pass = "";
        try {
            Class.forName ("com.mysql.jdbc.Driver").newInstance ();
            connection = DriverManager.getConnection (db_url, db_user, db_pass);
        }catch ( SQLException e ){System.out.println(e);}
        catch (InstantiationException e){System.out.println(e);} 
        catch (IllegalAccessException e){System.out.println(e);}
        catch (ClassNotFoundException e){System.out.println(e); }
    }

    public void executeQuery(String q) throws SQLException{
         stat = connection.createStatement();
         result = stat.executeQuery(q);
    }

    public void executeUpdate(String q) throws SQLException{
         stat = connection.createStatement();
         stat.executeUpdate(q);
    }

    public void execute(String q) throws SQLException{
         stat = connection.createStatement();
         if (stat.execute(q)){
             result = stat.getResultSet();
         }
    }
    public ResultSet getResultSet(){
        return result;
    }
}
